<SCRIPT LANGUAGE="JavaScript">  

    function swap(temp)
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = temp.checked;
        }
    }

    function check_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = true;
        }
        document.getElementById('checkall').checked = true;
    }

    function uncheck_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = false;
        }
        document.getElementById('checkall').checked = false;
    }
    
    function validation()
    {
        var pass = false;
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            if( document.getElementById('check'+i).checked == true )
            {
                pass = true;
            }
        
        }
        
        if(pass)
        { return confirm('Are you sure ?'); }
        else
        { alert('You must choose at least one of your applicant to be deleted'); return false; }
        
    }
 
    var xx = 100;
    var yy = 100;
    var tx = 0;
    var ty = 0;
    var dx = 0;
    var dy = 0;
    var klik = 0;
    
    function make_slip()
    {  
        xx=100;
        yy=100;
        klik=0;
        
        var temp = document.getElementById('slip');
        temp.style.position = 'absolute';
        temp.style.borderTop = '4px solid #ddd';
        temp.style.borderLeft = '4px solid #ddd';
        temp.style.borderBottom = '4px solid #aaa';
        temp.style.borderRight = '4px solid #aaa';
        temp.style.top = '100px';
        temp.style.left = '100px';
        temp.style.width = 'auto';
        temp.style.height = 'auto';
        temp.style.backgroundColor = 'white';
    }
    
    function close_slip()
    {  
        document.getElementById('slip').innerHTML = '';
        document.getElementById('slip').style.border = 'none';
    }
    
    function tekan(event)
    {
        klik = 1;
        tx=event.clientX;
        ty=event.clientY;
    }
    
    function gerak(event)
    {
        if(klik==1)
        {
            dx=event.clientX-tx;
            dy=event.clientY-ty;
            
            xx = xx + dx;
            yy = yy + dy;
            
            document.getElementById('slip').style.top = yy+'px';
            document.getElementById('slip').style.left = xx+'px';      
            
            tx=event.clientX;
            ty=event.clientY;
        }
    }    
    
    function lepas()
    {
        klik=0;
    }
 
    function open_win2(id)
    {
        window.open('../jobs/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }
 
    function open_win(id)
    {
        window.open('../employers/view/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=930, height=600");
    }
    
</SCRIPT>

<?php

   echo "<div class='form'>"; 
   echo "<h2> Saved Jobs </h2>";
   echo "<hr color='#2A7EF7'>";   
   echo ":. This page records all your online jobs applications at ITJobz.com.";

   if(!empty($applicants))
   {
        
       echo $this->element('myfunction');
       echo $form->create('Applicant',array('controller'=>'applicants','action'=>'my_applications','onsubmit'=>'return validation();'));

            echo "<table class='applicants' cellspacing=0 cellpadding=0>";
                $max = count($applicants);
                if($max < 10)
                { $max = 10; }
                echo "<input type='hidden' id='jumlah' name='data[jumlah]' value=".count($applicants).">";
            
                echo "<tr><th width='60px'><input type='checkbox' id='checkall' onClick='swap(this)'></th> <th width='100px'>Applied</th><th width='100px'>Post Date</th><th  width='250px'>Position</th><th width='180px'>Company</th><th width='150px'>Resume</th><th width='100px'>Job Status</th><th width='180px'>Applicant Status</th> </tr>";
                for($i=0;$i<$max;$i++)
                {
                    if(!empty($applicants[$i]))     
                    {
                        echo "<tr>";
                            echo "<td><input type='checkbox' name='data[check".$i."]' id='check".$i."' value=".$applicants[$i]['applicants']['id']."></td>";
                            echo "<td>".mydate($applicants[$i]['applicants']['created'])."</td>";
                            echo "<td>".mydate($applicants[$i]['jobs']['created'])."</td>";
                           // echo "<td>".$html->link($applicants[$i]['jobs']['position'],array('controller'=>'jobs','action'=>'view',$applicants[$i]['jobs']['id']),array('class'=>'blue'))."</td>";
                           //echo "<td>".$html->link($applicants[$i]['employers']['company_name'],array('controller'=>'employers','action'=>'view',$applicants[$i]['employers']['id']))."</td>";
                            
                            
                            echo "<td><a href='javascript:open_win2(".$applicants[$i]['jobs']['id'].")' class='sky'>".$applicants[$i]['jobs']['position']."</a></td>";
                            echo "<td><a href='javascript:open_win(".$applicants[$i]['employers']['id'].")'>".$applicants[$i]['employers']['company_name']."</a></td>";
                    
                            if($applicants[$i]['applicants']['resume']!=0)
                            { echo "<td>Resume Online</td>"; }
                            else
                            { echo "<td>Resume Attachment</td>"; }
                            if($applicants[$i]['jobs']['end_date']>=date("Y-m-d"))
                            { echo "<td> <span class='yes'>Open</span> </td>"; }
                            else
                            { echo "<td> <span class='no'>Closed</span> </td>"; }
                            
                            if($applicants[$i]['applicants']['status']==0)
                            { echo "<td> Waiting Confirmation </td>"; }
                            
                            if($applicants[$i]['applicants']['status']==1)
                            { 
                                echo "<td>";
                                //echo $html->link('View Reply',array('controller'=>'applicants','action'=>'view_reply',$applicants[$i]['applicants']['id'])); 
                                echo $ajax->link('View Reply', array('controller'=>'applicants','action'=>'view_reply',$applicants[$i]['applicants']['id']), array('update'=>'slip','complete'=>"make_slip();"));
                                if($applicants[$i]['applicants']['viewed']==0)
                                { echo " <font color='red'><sup><b>NEW</b></sup></font>"; }
                                echo "</td>";
                            }
                            
                            
                        echo "</tr>";
                    }
                    else
                    {
                        echo "<tr><td colspan=8></td></tr>";
                    }
                }
            echo "<tr class='end'><td class='end' colspan=8><input type='submit' value='Withdraw'>&nbsp&nbsp&nbsp <a href='Javascript:check_all();'>[ Select All ]</a>&nbsp&nbsp&nbsp <a href='Javascript:uncheck_all();'>[ Unselect All ]</a> </td></tr>";
            echo "</table>";
       echo "</form>";
        
        
        
     }
     else
     { echo "<br><span class='red'> &nbsp &nbsp You don't have any applications yet </span>"; }
     
     echo "</div>";
     echo "<div id='slip'></div>";
?>